<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>玉灵 QQ:7031633 Email:webrx@126.com</title>
    <style>
        .btnget,.btnpost{
            display: inline-block;
            width: 120px;
            height: 35px;
            text-align: center;
            border-radius: 5px;
            text-decoration: none;
            color:green;
            padding: 3px;
            border:1px solid gray;
            cursor: pointer;
        }

    </style>
</head>

<body>
<button class="btnget">fetch get</button>
<a href="javascript:void(0)" class="btnpost">fetch post</a>

<span id="t"></span>
<script>
    let btn = document.querySelector('.btnget')
    btn.addEventListener('click',function(){
        fetch('/pp1?id=6&name=李四').then(res=>res.json()).then(res=>{
            alert(res.name)
        }).catch(e=>console.log(e))
    })

    let btn2 = document.querySelector('.btnpost')
    btn2.addEventListener('click',function(){
        let id = 100
        let name = '张三丰'
        fetch('/pp3',{
            method:'post',
            body:JSON.stringify({id,name,address:'河南省郑州'}),
            headers:{'Content-Type': 'application/json'}
        }).then(res=>res.json()).then(res=>{
            alert(res.name)
        }).catch(e=>console.log(e))
    })

    let t = document.getElementById('t')
    function m(){
        fetch('/tt').then(r=>r.json()).then(res=>{
            t.innerHTML = res
        });
    }
    m()
    setInterval(m,1000)
</script>
</body>
</html>
